/**
 * @filename:JobLogController 2022-9-28
 * @project Wonder Java前后台分离框架  1.1.0
 * Copyright(c) 2020 Wonder Co. Ltd. 
 * All right reserved. 
 */
package com.wonder.admin.controller;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.wonder.admin.domain.JobLog;
import com.wonder.admin.service.JobLogService;
import com.wonder.admin.request.JobLogRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.wonder.common.common.AjaxMap;
import com.wonder.common.common.AjaxResult;
import com.wonder.common.common.CommonPage;
import com.wonder.common.utils.MessageUtils;
import com.wonder.common.utils.StringUtils;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiImplicitParam;
/**   
 * 
 * <p>说明： 任务日志API接口层</P>
 * @version: 1.1.0
 * @author: Wonder
 * @time    2022-9-28
 *
 */
@Api(tags = "任务日志")
@RestController
@RequestMapping("/admin/JobLog")
public class JobLogController {
	
	@Autowired
	private JobLogService jobLogService;
	
	@ApiOperation(value = "任务日志列表")
	@RequestMapping(value = "/index", method = RequestMethod.POST)
	public Map<String,Object> index(@RequestBody JobLogRequest jobLogRequest) {
		Page<JobLog> page = new Page<JobLog>(jobLogRequest.getPage(), jobLogRequest.getLimit());
		IPage<JobLog> list = jobLogService.selectList(jobLogRequest, page);
		
		Map<String,Object> retMap=new HashMap<>();
		retMap.put("data",CommonPage.restPage(list));
		
  
		return AjaxMap.success(retMap);
	}
	
	/**
	 * @explain 修改排序开关
	 * @param   对象参数：JobLog
	 * @return  Boolean
	 * @author  Wonder
	 */
	@PostMapping("/updateExt")
	@ApiOperation(value = "修改排序开关", notes = "作者：Wonder")
	public AjaxResult<JobLog> updateExt(@RequestBody JobLog entity){
		if (null!=entity) {
			boolean rsg = jobLogService.updateById(entity);
			if (rsg) {
				  return AjaxResult.success("system.success");
			  }else {
				  return AjaxResult.failed("system.fail");
			  }
		}else {
			return AjaxResult.failed("system.parameterError");
		}
	}
	
	/**
	 * @explain 添加
	 * @param   对象参数：JobLog
	 * @return  Boolean
	 * @author  Wonder
	 */
	@PostMapping("/add")
	@ApiOperation(value = "添加", notes = "作者：Wonder")
	public AjaxResult<JobLog> add(@RequestBody JobLog entity){

		if (null!=entity) {
		    
		    String validate=jobLogService.validate(entity,"new");
		    if(StringUtils.hasText(validate))
		         return AjaxResult.failed(validate);    
			boolean rsg = jobLogService.save(entity);
			if (rsg) {
				  return AjaxResult.success("system.success");
			  }else {
				  return AjaxResult.failed("system.fail");
			  }
		}else {
			return AjaxResult.failed("system.parameterError");
		}
	}
	
	/**
	 * @explain 查看对象明细  
	 * @param   对象参数：id
	 * @return  JsonResult
	 * @author  Wonder
	 */
	@PostMapping("/detail")
	@ApiOperation(value = "获取任务日志对象明细", notes = "作者：Wonder")
	public AjaxResult<JobLog> detail(@RequestBody Map<String,Object> map){
	    if(map==null) AjaxResult.failed("system.parameterError");
		Long id=Long.parseLong(map.get("id").toString());		
		JobLog jobLog=jobLogService.getById(id);
		if (null!=jobLog ) {	
			 return AjaxResult.success(jobLog);
		}else {
			 return AjaxResult.failed("system.parameterError");
		}
		
	}
	
	/**
	 * @explain 导出数据
	 * @param   对象参数：JobLog
	 * @return  Map<String,Object>
	 * @author  Wonder
	 */
	@PostMapping("/dumpdata")
	@ApiOperation(value = "导出数据", notes = "作者：Wonder")
	public Map<String,Object> dumpdata(@RequestBody JobLogRequest jobLogRequest) {
		return jobLogService.dumpdata(jobLogRequest);
	}
	
	
}